#########################################################################
## Customize your APP title, subtitle and menus here
#########################################################################

response.title = request.application
response.subtitle = T('customize me!')

##########################################
## this is the authentication menu
## remove if not necessary
##########################################

if 'auth' in globals() and request.function == 'user':
    if not auth.is_logged_in():
       response.menu_auth = [
           [T('Login'), False, URL(request.application,'default','user/login'),
            [
                   [T('Register'), False,
                    URL(request.application,'default','user/register')],
                   [T('Lost Password'), False,
                    URL(request.application,'default','user/retrieve_password')]]
            ],
           ]
    else:
        response.menu_auth = [
            ['User: '+auth.user.first_name,False,None,
             [
                    [T('Logout'), False, 
                     URL(request.application,'default','user/logout')],
                    [T('Edit Profile'), False, 
                     URL(request.application,'default','user/profile')],
                    [T('Change Password'), False,
                     URL(request.application,'default','user/change_password')]]
             ],
            ]

##########################################
## this is the main applicaiton menu
## add/remove items as required
##########################################


#cuxiao 准备废掉
if request.controller == 'cuxiao':
    response.menu = [
        [request.application, False, 
         URL(request.application,'default','index'), [
            ['Add', False,
                URL(request.application, 'default', 'add')],
            ['Data', False,
                URL(request.application, 'default', 'data')],
            ]],
        ['收藏', False,
         URL(request.application, 'cuxiao', 'favorite')],
        ['已经购买', False,
         URL(request.application, 'cuxiao', 'purchased')],
        ['帮助', False,
         URL(request.application, 'cuxiao', 'help')],
        ['OtherApp', False,
         URL(request.application, 'cuxiao', 'otherapp')],
        ]
    if session.user_name:
        response.menu.insert(1,
            [session.user_name, False, 
             URL(request.application,'cuxiao','setting', args=session.userId), []])
# default 控制器下的 Menu
elif request.controller == 'default':
    response.menu = [
        [request.application.capitalize(), False, 
         URL(request.application, 'default', 'index'), [
            ['Template', False,
                URL(request.application, 'template', 'index')],
            ]],
        ]
    # 登陆后显示 data 菜单
#    if 'auth' in globals():
#        if auth.is_logged_in():
#            response.menu.insert(1,
#                ['Data', False,
#                    URL(request.application, 'default', 'data'), []])
    # 登陆后在 data 下 显示 user 菜单
    if request.function == 'data':
        if 'auth' in globals():
            if auth.is_logged_in():
                response.menu.insert(2,
                    ['User: '+auth.user.first_name,False,None,
                        [
                            [T('Logout'), False, 
                             URL(request.application,'default','user/logout')],
                            [T('Edit Profile'), False, 
                             URL(request.application,'default','user/profile')],
                            [T('Change Password'), False,
                             URL(request.application,'default','user/change_password')]]
                     ]
                    )
# template 控制器下的 Menu
elif request.controller == 'template':
    response.menu = [
        ['<<'+request.application.capitalize(), False, 
         URL(request.application, 'default', 'index'), [
            ]],
        ['Add', True,
         URL(request.application, 'template', 'add'), []],
        ['Edit', False,
         URL(request.application, 'template', 'edit'), []],
        ]
else:
    response.menu = [
        [request.application.capitalize(), False, 
         URL(request.application, 'default', 'index'), []],
        ]


##########################################
## this is here to provide shortcuts
## during development. remove in production 
##########################################

if request.function == 'data':
    response.menu_edit=[
      ['Edit', False, URL('admin', 'default', 'design/%s' % request.application),
       [
                ['Controller', False, 
                 URL('admin', 'default', 'edit/%s/controllers/default.py' \
                         % request.application)],
                ['View', False, 
                 URL('admin', 'default', 'edit/%s/views/%s' \
                         % (request.application,response.view))],
                ['Layout', False, 
                 URL('admin', 'default', 'edit/%s/views/layout.html' \
                         % request.application)],
                ['Stylesheet', False, 
                 URL('admin', 'default', 'edit/%s/static/base.css' \
                         % request.application)],
                ['DB Model', False, 
                 URL('admin', 'default', 'edit/%s/models/db.py' \
                         % request.application)],
                ['Menu Model', False, 
                 URL('admin', 'default', 'edit/%s/models/menu.py' \
                         % request.application)],
                ['Database', False, 
                 URL(request.application, 'appadmin', 'index')],
                ]
       ],
      ]
